home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrecord-1.8.1 / lib / getav0.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  2.4 KB  |  111 lines

  1. /* @(#)getav0.c    1.9 99/09/11 Copyright 1985 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)getav0.c    1.9 99/09/11 Copyright 1985 J. Schilling";
  5. #endif
  6. /*
  7.  *    Get arg vector by scanning the stack
  8.  *
  9.  *    Copyright (c) 1985 J. Schilling
  10.  */
  11. /*
  12.  * This program is free software; you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation; either version 2, or (at your option)
  15.  * any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program; see the file COPYING.  If not, write to
  24.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  25.  */
  26.  
  27. #include <mconfig.h>
  28. #include <sigblk.h>
  29. #include <avoffset.h>
  30. #include <standard.h>
  31.  
  32. #if    !defined(AV_OFFSET) || !defined(FP_INDIR)
  33. #    ifdef    HAVE_SCANSTACK
  34. #    undef    HAVE_SCANSTACK
  35. #    endif
  36. #endif
  37. #ifdef    NO_SCANSTACK
  38. #    ifdef    HAVE_SCANSTACK
  39. #    undef    HAVE_SCANSTACK
  40. #    endif
  41. #endif
  42.  
  43. #ifdef    HAVE_SCANSTACK
  44.  
  45. #include <stkframe.h>
  46.  
  47. #define    is_even(p)    ((((long)(p)) & 1) == 0)
  48. #define    even(p)        (((long)(p)) & ~1L)
  49. #ifdef    __future__
  50. #define    even(p)        (((long)(p)) - 1)/* will this work with 64 bit ?? */
  51. #endif
  52.  
  53. char **getavp()
  54. {
  55.     register struct frame *fp;
  56.     register struct frame *ofp;
  57.          char    **av;
  58. #if    FP_INDIR > 0
  59.     register int    i = 0;
  60. #endif
  61.  
  62.     ofp = fp = (struct frame *)getfp();
  63.     while (fp) {
  64.  
  65. #if    FP_INDIR > 0
  66.         i++;
  67. #endif
  68.         ofp = fp;
  69.         if (!is_even(fp->fr_savfp)) {
  70.             fp = (struct frame *)even(fp->fr_savfp);
  71.             fp = (struct frame *)((SIGBLK *)fp)->sb_savfp;
  72.             continue;
  73.         }
  74.         fp = fp->fr_savfp;
  75.     }
  76.  
  77. #if    FP_INDIR > 0
  78.     i -= FP_INDIR;
  79.         ofp = fp = (struct frame *)getfp();
  80.     while (fp) {
  81.         if (--i < 0)
  82.             break;
  83.         ofp = fp;
  84.         if (!is_even(fp->fr_savfp)) {
  85.             fp = (struct frame *)even(fp->fr_savfp);
  86.             fp = (struct frame *)((SIGBLK *)fp)->sb_savfp;
  87.             continue;
  88.         }
  89.         fp = fp->fr_savfp;
  90.     }
  91. #endif
  92.  
  93.         av = (char **)ofp + AV_OFFSET;    /* aus avoffset.h */
  94.                     /* (wird generiert mit av_offset) */
  95.     return (av);
  96. }
  97.  
  98. char *getav0()
  99. {
  100.     return (getavp()[0]);
  101. }
  102.  
  103. #else
  104.  
  105. char *getav0()
  106. {
  107.     return ("???");
  108. }
  109.  
  110. #endif    /* HAVE_SCANSTACK */
  111.